/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Ale
 */
public class Validar {

public static boolean esValidoNum(String s) {
        try {
            Integer.parseInt(s);
            return true;
        } catch (NumberFormatException nfe) {
            return false;
        }
    }

    public static boolean esValidoDecimal(String s){
        Pattern pc = Pattern.compile("(-)?(\\d){1,3}(.(\\d){3})*(,(\\d){1,2})?");
        Matcher m = pc.matcher(s);
        boolean valido = m.matches();
        return valido;
    }

    
    public static boolean esValidoChar(String s) {
        boolean res;
        Pattern p = Pattern.compile("^[a-zA-Z0-9-]+$");
        Matcher m = p.matcher(s);
        if (m.find()) {
            res = true;
        } else {
            res = false;
        }
        return res;
    }

    public static boolean archivoXls(String s){
        Pattern p = Pattern.compile("(*.xls)");
        Matcher m = p.matcher(s);
        boolean valido = m.matches();
        return valido;
    }

    public static boolean esFecha(String fecha){
        Pattern p = Pattern.compile("(19|20[0-9]{2})[-](0[1-9]|1[012])[-](0[1-9]|[12][0-9]|3[01])");
        Matcher m = p.matcher(fecha);
        boolean valido = m.matches();
        return valido;
    }
    
    
    public static boolean isDate(String fechax) {
        try {
            SimpleDateFormat formatoFecha = new SimpleDateFormat("yyyy-MM-dd");
            formatoFecha.setLenient(false);
            Date fecha = formatoFecha.parse(fechax);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    
}
